package ru.tpu.osu.faces.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.*;

import ru.tpu.osu.faces.dao.*;

@ManagedBean(name="teacherBean")
@RequestScoped
public class TeacherBean extends BaseBean implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 2334648517659556829L;
	private Teacher teacher;
	private String login;
	private List<Discipline> lectureDisciplines;
	private List<Discipline> laboratoryDisciplines;
	private List<Discipline> practiceDisciplines;
	  
	public List<Discipline> getLaboratoryDisciplines() {
		if (laboratoryDisciplines == null) {
			if (getTeacher() == null) {
				laboratoryDisciplines = new ArrayList<Discipline>();
			} else {
				laboratoryDisciplines = getTeacher().getLaboratoryDisciplines();
			}
		}
		return laboratoryDisciplines;
	}

	public List<Discipline> getPracticeDisciplines() {
		if (practiceDisciplines == null) {
			if (getTeacher() == null) {
				practiceDisciplines = new ArrayList<Discipline>();
			} else {
				practiceDisciplines = getTeacher().getPracticeDisciplines();
			}
		}
		return practiceDisciplines;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public String getLogin() {
		return login;
	}

	public List<Discipline> getLectureDisciplines() {
		if (lectureDisciplines == null) {
			if (getTeacher() == null) {
				lectureDisciplines = new ArrayList<Discipline>();
			} else {
				lectureDisciplines = getTeacher().getLectureDisciplines();
			}
		}
		return lectureDisciplines;
	}

	public void setLogin(String login) {
		if (login != null) {
			teacher = (Teacher) HibernateUtil.getSession().get(Teacher.class, login);
			HibernateUtil.getSession().refresh(teacher);
		}
	
		this.login = login;
	}
}

